package com.java110.mall.goods.cmd.productCategory;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.Environment;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.mall.goods.bmo.mainCategoryProduct.IUpdateMainCategoryProductBMO;
import com.java110.po.mainCategory.MainCategoryProductPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "productCategory.updateMainCategoryProduct")
public class UpdateMainCategoryProductCmd extends Cmd {


    @Autowired
    private IUpdateMainCategoryProductBMO updateMainCategoryProductBMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Environment.isDevEnv();
        Assert.hasKeyAndValue(reqJson, "mainCategoryId", "请求报文中未包含mainCategoryId");
        Assert.hasKeyAndValue(reqJson, "productId", "请求报文中未包含productId");
        Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含startTime");
        Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含endTime");
        Assert.hasKeyAndValue(reqJson, "seq", "请求报文中未包含seq");
        Assert.hasKeyAndValue(reqJson, "mcProductId", "mcProductId不能为空");

    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        MainCategoryProductPo mainCategoryProductPo = BeanConvertUtil.covertBean(reqJson, MainCategoryProductPo.class);
        ResponseEntity<String> responseEntity =  updateMainCategoryProductBMOImpl.update(mainCategoryProductPo);
        context.setResponseEntity(responseEntity);
    }
}
